﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AlgoritmenEindCase
{
    public partial class Form1 : Form
    {
        /// <summary>
        /// Posities van de stenen.
        /// Eerste cijfer is Verticale positie op bord
        /// Tweede cijfer is Horizontale positie op bord
        /// Derde cijfer geeft aan of het om de X of Y gaat van de positie van de picturebox. 0 is X, 1 is Y.
        /// </summary>
        int[,,] steenposities = new int[8, 4, 2];

        /// <summary>
        /// Bool die aangeeft of er met een steen wordt gesleept
        /// </summary>
        private bool isDragging = false;

        private int currentX, currentY;

        Rectangle dropRect = new Rectangle(180, 180, 60, 60);

        /// <summary>
        /// Initialiseren van het form
        /// </summary>
        public Form1()
        {
            InitializeComponent();
            loadSteenPosities();
            loadStartstones(this, steenposities);
        }

        /// <summary>
        /// Initialiseren van de steenposities in het array
        /// </summary>
        private void loadSteenPosities()
        {
            int x = 94;
            int y = 20;
            bool even = false;
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    steenposities[i, j, 0] = x;
                    steenposities[i, j, 1] = y;
                    x = x + 151;
                }
                if (even)
                {
                    x = 94;
                    even = false;
                }
                else
                {
                    x = 20;
                    even = true;
                }
                y = y + 75;
            }

        }

        private void loadStartstones(Control parant, int[, ,] steenposities)
        {
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (i == 3 || i == 4)
                    { }
                    else
                    {
                        PictureBox steen = new System.Windows.Forms.PictureBox();
                        steen.BackColor = System.Drawing.Color.Black;
                        if (i < 4)
                            steen.Image = global::AlgoritmenEindCase.Properties.Resources.steen_rood;
                        else
                            steen.Image = global::AlgoritmenEindCase.Properties.Resources.steen_blauw;
                        steen.Location = new System.Drawing.Point(steenposities[i, j, 0], steenposities[i, j, 1]);
                        steen.Name = "steen_rood_Pb";
                        steen.Size = new System.Drawing.Size(60, 60);
                        steen.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
                        steen.TabIndex = 1;
                        steen.TabStop = false;
                        steen.BringToFront();
                        steen.MouseUp += new MouseEventHandler(steen_MouseUp);
                        steen.MouseDown += new MouseEventHandler(steen_MouseDown);
                        steen.MouseMove += new MouseEventHandler(steen_MouseMove);
                        steen.Cursor = Cursors.Hand;
                        this.Controls.Add(steen);
                        spelbord_Pb.SendToBack();
                    }
                }
            }
        }

        void steen_MouseMove(object sender, MouseEventArgs e)
        {
            PictureBox pb = sender as PictureBox;
            if (isDragging)
            {
                pb.Top = pb.Top + (e.Y - currentY);
                pb.Left = pb.Left + (e.X - currentX);
            }
        }

        void steen_MouseUp(object sender, MouseEventArgs e)
        {
            isDragging = false;
        }

        void steen_MouseDown(object sender, MouseEventArgs e)
        {
            isDragging = true;
            currentX = e.X;
            currentY = e.Y;
        }
        

    }
}
